/*
Copyright (C) 2009  Raymond Jeon
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/






#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#include "gl_lib_include.h"
#include "gl_mail_define.h"
#include "gl_mail_gdata.h"
#include "gl_mail_config.h"
#include "gl_mail_main.h"
#include "gl_mail_log.h"
#include "gl_mail_getopt.h"
#include "gl_mail_mainparent.h"
#include "gl_mail_mainchild.h"
#include "gl_mail_init.h"






void GlCalMd5( char* pSrc, int nLen, char* pMD5 );
void testtest()
{
char szMD5[_MAXPATH+1];

GlCalMd5("aaaa", _MAXPATH, szMD5);
printf("%s\n", szMD5);
}






static void GlHelpMain()
{
	printf("This program is a mail server(%s) for windows platforms\n", GLSERVERVERSION);
	printf("This is contains SMTP(25 port) server, POP3(110 port) server and SMMP(2525 port) server.\n");
	printf("Use this commands\n");
	printf(APP_NAME".exe -i [mail service install]\n");
	printf(APP_NAME".exe -u [mail service uninstall]\n");
	printf(APP_NAME".exe -r [mail service uninstall and reinstall]\n");
	printf(APP_NAME".exe -h [help]\n");
	printf(APP_NAME".exe    [mail service execute]\n");
}

////////////////////////////////////////////////////////////////////////////////
//	Date : 2003-2-20
//	Update : 
//	Author : Raymond Jeon
//	Parameters
//	Return Value  
//	Remarks 
////////////////////////////////////////////////////////////////////////////////

int main(int argc, char *argv[]) 
{
	int iExeMode;

//	testtest();

	GlGolbalPathInit();

	if(AllocConsole()) 	
	{
		FreeConsole();
		GLTRACE("Windows Service Start");
		GlMailServerParentInit();
        GlServiceMain(GlParentMain, argc, argv, GLSERVICENAME);
		exit(0);
	}
	
	iExeMode = GlMainGetOption(argc, argv);

	switch (iExeMode)
	{
	case EXEMODE_PARENT		:
		GlMailServerParentInit();
		GlParentMain(argc, argv);
		break;
	case EXEMODE_CHILD		:
		GlMailServerChildInit();
		GlChildMain(argc, argv);
		break;
	case EXEMODE_INSTALL	:
		GlInstallServiceMain();
		break;
	case EXEMODE_REINSTALL	:
		GlReinstallServiceMain();
		break;
	case EXEMODE_UNINSTALL		:
		GlUninstallServiceMain();
		break;
	case EXEMODE_HELP		:
		GlHelpMain();
		break;
	default :
		GlMailServerParentInit();
		GlParentMain(argc, argv);
		break;
	}


	GlSockCleanup();
	return TRUE;
}


